'use strict'

let templateConfig = require('../../config/templateConfig')
let itemComponent = require('./itemComponent')
let utils = require('../utils/utils')
let montserAttriConfig = templateConfig.other[290001]

class MonsterComponent {
  constructor(opts) {
    this.name = opts.name || '' //怪物名
    if (opts.fightAttri) {
      this.fightAttri = new FightAttri(opts.fightAttri) //战斗属性
    } else {
      let lvl = opts.lvl || 1
      this.fightAttri = new FightAttri({
        maxHp: montserAttriConfig.maxHp[0] * lvl + montserAttriConfig.maxHp[1], //生命
        attack: montserAttriConfig.attack[0] * lvl + montserAttriConfig.attack[1], //攻击力
        defend: montserAttriConfig.defend[0] * lvl + montserAttriConfig.defend[1], //防御
        lvl: lvl,
      })
    }

  }

  getFightAttriCopy() {
    let fightAttri = new FightAttri(this.fightAttri)
    fightAttri.hp = this.fightAttri.hp
    return fightAttri
  }

  getAllFightAttriCopy() {
    let fightAttri = new FightAttri(this.fightAttri)
    fightAttri.hp = this.fightAttri.maxHp
    return fightAttri
  }

  initFightAttri() {
    this.fightAttri.buff = 0
    this.fightAttri.debuff = 0
    return this.fightAttri
  }
}

//战斗属性
class FightAttri {
  constructor(opts) {
    this.hp = opts.maxHp || 0 //生命
    this.maxHp = opts.maxHp || 0 //最大生命
    this.attack = opts.attack || 0 //攻击力
    this.defend = opts.defend || 0 //防御
    this.critRate = opts.critRate || 0 //暴击概率
    this.critHurt = opts.critHurt || 0 //暴击伤害
    this.ignoreDefend = opts.ignoreDefend || 0 //无视防御力
    this.skillRate = opts.skillRate || 0 //单体技能释放率
    this.skillHurtPer = opts.skillHurtPer || 0 //技能伤害率
    this.attackSkill = opts.attackSkill || [] //攻击触发技能
    this.defendSkill = opts.defendSkill || [] //防御触发技能
    this.prefixAttriId = opts.prefixAttriId || 0 //前缀属性
    this.lvl = opts.lvl || 1 //等级
    this.buff = 0 //0初始状态
    this.debuff = 0 //0初始状态 1 眩晕
    this.skills = this.attackSkill.concat(this.defendSkill)
  }
}

module.exports = MonsterComponent
